//
//  PickNumP3ListViewController.m
//  PlayBall
//
//  Created by Sun Fanglei on 13-5-17.
//
//

#import "JddPickNumP3ListViewController.h"
#import "JddViewControllerManager.h"

@interface JddPickNumP3ListViewController ()

@end

@implementation JddPickNumP3ListViewController

SHARED_VIEW_CONTROLLER_IMPLEMENT(JddPickNumP3ListViewController);

@synthesize mutiTextField;
@synthesize lotNumListTableView;
@synthesize countLabel;
@synthesize moneyLabel;
@synthesize PlayMethodTemp;
@synthesize PlayMethod;
@synthesize currentLotteryIssue;
@synthesize bgScrollView;
@synthesize buybutton;
@synthesize numberArray;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
- (void)viewWillDisappear:(BOOL)animated
{
    [MobClick endLogPageView:@"PL3-list"];

    if ([mutiTextField.text length]==0) {
        mutiTextField.text = @"1";
    }
    [mutiTextField resignFirstResponder];
}
-(void)viewWillAppear:(BOOL)animated{
    [MobClick beginLogPageView:@"PL3-list"];

    currentLotteryIssue = [[JddLotteryIssue alloc] init];
    
    if (isNeedAdd == false) {
        return;
    }
    isNeedAdd = false;
    if (PlayMethod!=PlayMethodTemp&&PlayMethod!=0) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
                                                        message:@"一个方案只能有一种玩法，如果继续将清空以前所选号码，确认清空列表？"
                                                       delegate:self
                                              cancelButtonTitle:@"确定"
                                              otherButtonTitles:@"取消",nil ];
        [alert show];
    }else{
        [numberArray addObjectsFromArray:numberArrayTemp];
        [lotNumListTableView reloadData];
        //把新选择的号码添加进去，并从新计算注数
        //计算注数
        noteAmount = 0;
        for (JddFc3dNumber *inNums in numberArray) {
            switch (PlayMethod) {
                case 6302://直选
                    noteAmount += [[inNums BallArray] count]*[[inNums SecondBallArray] count]*[[inNums ThirdBallArray] count];
                    break;
                case 6305://组选三
                    noteAmount += [[inNums BallArray] count]*([[inNums BallArray] count] - 1);
                    break;
                case 6304://组选六
                    if ([[inNums BallArray] count] > 2) {
                        noteAmount += [JddCommonFunction recurseBallNumber:[[inNums BallArray] count]combinationNumber:3];
                    }
                    break;
                default:
                    break;
            }
            
        }
        moneyLabel.text = [NSString stringWithFormat:@"%d彩豆",noteAmount*2*[mutiTextField.text intValue]];
        countLabel.text = [NSString stringWithFormat:@"%d注",noteAmount];
    }
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    agreeLotteryForFooterView = [JddAgreeLotteryForFooterView getInstanceView];
    agreeLotteryForFooterView.fromViewController = self;
    lotNumListTableView.tableFooterView = agreeLotteryForFooterView;
//    [self.navigationItem setTitle:PAGE_P3_PICK_NUMBER_LIST];
    
        UILabel *customLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
        customLab.backgroundColor = [UIColor clearColor];
        [customLab setText:PAGE_P3_PICK_NUMBER_LIST];
        customLab.textAlignment = NSTextAlignmentCenter;

        [customLab setTextColor:[UIColor whiteColor]];
        customLab.font = [UIFont systemFontOfSize:19];
        self.navigationItem.titleView = customLab;
        
//        //self.navigationItem.hidesBackButton = YES;
    if (!numberArray) {
        numberArray = [[NSMutableArray alloc] init];
    }
}

//- (void)back
//{
//    [self.navigationController popViewControllerAnimated:YES];
//}

- (void)viewDidUnload {
    [self setLotNumListTableView:nil];
    [self setMutiTextField:nil];
    [self setCountLabel:nil];
    [self setMoneyLabel:nil];
    [self setBgScrollView:nil];
    [self setBuybutton:nil];
    [super viewDidUnload];
}

-(void)destoryView{
    numberArray = [[NSMutableArray alloc] init];
    numberArrayTemp = [[NSMutableArray alloc] init];
    [lotNumListTableView reloadData];
    PlayMethod = 0;
    PlayMethodTemp = 0;
    noteAmount = 0;
    [mutiTextField resignFirstResponder];
    mutiTextField.text  = @"1";
    countLabel.text = @"0注";
    moneyLabel.text = @"0彩豆";
}

- (IBAction)coBuyBtnClick:(id)sender {
    if([self checkValue]){
    JddLotteryIssue *ls = ((JddPickNumP3ViewController *)self.fromController).currentLotteryIssue;
    [FaQiHeMaiViewController sharedInstance].bs = [mutiTextField.text intValue];
    [FaQiHeMaiViewController sharedInstance].lotID = LOTTERY_TYPE_ID_PL3;
    [FaQiHeMaiViewController sharedInstance].issueID = ls.code;
    [FaQiHeMaiViewController sharedInstance].issueName = ls.name;
    [FaQiHeMaiViewController sharedInstance].issueNameTitle = [NSString stringWithFormat:@"排列三第%@期合买",ls.name];
    [FaQiHeMaiViewController sharedInstance].allMoney = noteAmount * [mutiTextField.text intValue] * 2;
    [FaQiHeMaiViewController sharedInstance].lotteryNumber = [self lotteryNumberList];
    [[JddViewControllerManager sharedInstance].navigationController pushViewController:[FaQiHeMaiViewController sharedInstance] animated:YES];
    }
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if ([[alertView message] isEqualToString:@"一个方案只能有一种玩法，如果继续将清空以前所选号码，确认清空列表？"]) {
        if (buttonIndex == 0) {
            PlayMethod = PlayMethodTemp;
            [numberArray removeAllObjects];
            [numberArray addObjectsFromArray:numberArrayTemp];
            [lotNumListTableView reloadData];
            //把新选择的号码添加进去，并从新计算注数
            //计算注数
            noteAmount = 0;
            for (JddFc3dNumber *inNums in numberArray) {
                switch (PlayMethod) {
                    case 6302://直选
                        noteAmount += [[inNums BallArray] count]*[[inNums SecondBallArray] count]*[[inNums ThirdBallArray] count];
                        break;
                    case 6305://组选三
                        noteAmount += [[inNums BallArray] count]*([[inNums BallArray] count] - 1);
                        break;
                    case 6304://组选六
                        if ([[inNums BallArray] count] > 2) {
                            noteAmount += [JddCommonFunction recurseBallNumber:[[inNums BallArray] count]combinationNumber:3];
                        }
                        break;
                    default:
                        break;
                }
                
            }
            moneyLabel.text = [NSString stringWithFormat:@"%d彩豆",noteAmount*2*[mutiTextField.text intValue]];
            countLabel.text = [NSString stringWithFormat:@"%d注",noteAmount];
            
        }else if (buttonIndex == 1){
            numberArrayTemp = [[NSMutableArray alloc] init];
        }
    }else if ([[alertView message] isEqualToString:@"确认清空列表？"]){
        if (buttonIndex == 0) {
            [numberArray removeAllObjects];
            [numberArrayTemp removeAllObjects];
            [lotNumListTableView reloadData];
            PlayMethodTemp = 0;
            noteAmount = 0;
            mutiTextField.text  = @"1";
            countLabel.text = @"0注";
            moneyLabel.text = @"0彩豆";
        }
    }if ([[alertView message] isEqualToString:@"确认购买？"]) {
        if (buttonIndex==0) {
            [self sureToBuy];
        }
    }else if ([[alertView message] isEqualToString:@"您还没有登录，请先登录"]) {
        if (buttonIndex == 0) {
            [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_LOGIN
                                                                 fromController:self
                                                                     withObject:nil
                                                                    withObject2:nil];
        }
    }
}

-(void)sureToBuy{
    if ([self checkValue]) {
    [JddCommonFunction setWaitingViewHidden:NO fromController:self];
    JddBuyLotteryOperation *operation2 = [[JddBuyLotteryOperation alloc] init];
    operation2.delegate = self;
    JddLotteryIssue *ls = ((JddPickNumP3ListViewController*)self.fromController).currentLotteryIssue;
    operation2.lotteryTypeId = [NSNumber numberWithInt:63];
    operation2.issueId = [NSNumber numberWithInt:[ls.code intValue]];
    operation2.multiple = [NSNumber numberWithInt:[mutiTextField.text intValue]];
    operation2.moneyAmount = [NSNumber numberWithFloat:noteAmount * [mutiTextField.text intValue] * 2];
    operation2.lotteryNumber = [self lotteryNumberList];
    [[JddGlobalParameter sharedInstance].operationQueue addOperation:operation2];
    }
}

-(void)BuyLotteryOperationResult:(NSData *)result{
    [JddCommonFunction setWaitingViewHidden:YES fromController:self];
    if (result) {
        
        NSDictionary *ReDic = [NSJSONSerialization JSONObjectWithData:result options:NSJSONReadingMutableContainers error:nil];
        if([[ReDic objectForKey:@"Code"] intValue] == 0)
        {
            // modify by rainy  修改投注使用接口不经过web
            NSString * fanganhao = [ReDic objectForKey:@"Data"];
            JddLotteryIssue *ls = ((JddPickNumP3ViewController *)self.fromController).currentLotteryIssue;
            alert1 = [JddAlertView getInstanceView];
            alert1.lssueString = fanganhao;
            alert1.moneylable = moneyLabel.text;
            [alert1 alertBuyMessage:[NSString stringWithFormat:@"排列三%@期",ls.name]];
//            NSString*checkUrlString = [NSString stringWithFormat:@"%@?ck=%@",BASE_SERVER_IOS_BUY_LOTTERY_URL,[ReDic objectForKey:@"Data"]];
//            NSURL *checkUrl = [NSURL URLWithString:checkUrlString];
//            [[UIApplication sharedApplication] openURL:checkUrl];
        }else{
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"购彩失败"                                                  message:[ReDic objectForKey:@"Data"] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil,nil ];
            [alert show];
        }
//        [JddCommonFunction updateBuyLotteryListWithLotteryId:LOTTERY_TYPE_ID_PL3];

    }
}

-(NSMutableArray*)lotteryNumberList{
    NSMutableArray *paramNumberArray = [[NSMutableArray alloc] init];
    if (PlayMethod == 6302) {
        int playid = PlayMethod;
        for (JddFc3dNumber *inNum in numberArray) {
            NSMutableString *lotString = [NSMutableString string];
            NSMutableDictionary *numDic = [[NSMutableDictionary alloc] init];
            if (([[inNum ballNum] length] == 1) && ([[inNum ball2Num] length] ==1) && ([[inNum ball3Num] length] == 1)) {
                playid = 6301;
                [lotString appendFormat:@"%@%@%@",[inNum ballNum],[inNum ball2Num],[inNum ball3Num]];
            }else{
                playid = 6302;
                if ([[inNum ballNum] length] == 1) {
                    [lotString appendFormat:@"%@",[inNum ballNum]];
                }else{
                    [lotString appendFormat:@"(%@)",[inNum ballNum]];
                }
                if ([[inNum ball2Num] length] == 1) {
                    [lotString appendFormat:@"%@",[inNum ball2Num]];
                }else{
                    [lotString appendFormat:@"(%@)",[inNum ball2Num]];
                }
                if ([[inNum ball3Num] length] == 1) {
                    [lotString appendFormat:@"%@",[inNum ball3Num]];
                }else{
                    [lotString appendFormat:@"(%@)",[inNum ball3Num]];
                }
            }
            [numDic setObject:[NSNumber numberWithInt:playid] forKey:@"playid"];
            [numDic setObject:lotString forKey:@"number"];
            [paramNumberArray addObject:numDic];
        }
    }
    else if (PlayMethod == 6305 || PlayMethod == 6304){
        for (JddFc3dNumber *inNum in numberArray) {
            NSMutableDictionary *numDic = [[NSMutableDictionary alloc] init];
            [numDic setObject:[NSNumber numberWithInt:PlayMethod] forKey:@"playid"];
            [numDic setObject:[inNum ballNum] forKey:@"number"];
            [paramNumberArray addObject:numDic];
        }
    }
    return paramNumberArray;
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    [mutiTextField resignFirstResponder];
    return YES;
}

-(BOOL)textFieldShouldClear:(UITextField *)textField{
    return NO;
}

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTapGesture:)];
    tapGestureRecognizer.delegate = self;
    [self.bgScrollView addGestureRecognizer:tapGestureRecognizer];
    
    [self.bgScrollView setContentOffset:CGPointMake(0,213/*buybutton.frame.size.height + buybutton.frame.origin.y - mutiTextField.frame.origin.y + mutiTextField.frame.size.height*2+20*/)animated:YES];
    return YES;
}

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
    
    if ([touch.view isDescendantOfView:buybutton]) {
        return NO;
    }
    
    return YES;
}

- (IBAction)handleSingleTapGesture:(UITapGestureRecognizer*)sender{
    [mutiTextField resignFirstResponder];
    if ([mutiTextField.text length]==0) {
        mutiTextField.text = @"1";
    }
    moneyLabel.text = [NSString stringWithFormat:@"%d彩豆", noteAmount * [mutiTextField.text intValue] * 2];
    [self.bgScrollView removeGestureRecognizer:sender];
    [self.bgScrollView setContentOffset:CGPointMake(0, 0) animated:YES];
}

-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    
    NSCharacterSet *cs;
    cs = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789\n"]invertedSet];
    
    NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs]componentsJoinedByString:@""]; //按cs分离出数组,数组按@""分离出字符串
    
    BOOL canChange = [string isEqualToString:filtered];
    
    if (!canChange) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
                                                        message:@"倍数只能输入数字"
                                                       delegate:nil
                                              cancelButtonTitle:@"确定"
                                              otherButtonTitles:nil,nil ];
        [alert show];
        return NO;
    }
    if ([string length] + range.location>3) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
                                                        message:@"倍数不能大于999"
                                                       delegate:nil
                                              cancelButtonTitle:@"确定"
                                              otherButtonTitles:nil,nil ];
        [alert show];
        return NO;
    }
    
    if ([textField.text length]== 0) {
        if ([string isEqualToString:@"0"]) {
            return NO;
        }else {
            moneyLabel.text = [NSString stringWithFormat:@"%d彩豆", noteAmount * [[textField.text stringByReplacingCharactersInRange:range withString:string] intValue] * 2];
            return YES;
        }
        
    }
    if (range.location >=3) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
                                                        message:@"倍数不能大于999"
                                                       delegate:nil
                                              cancelButtonTitle:@"确定"
                                              otherButtonTitles:nil,nil ];
        [alert show];
        return NO;
    }else {
        moneyLabel.text = [NSString stringWithFormat:@"%d彩豆", noteAmount * [[textField.text stringByReplacingCharactersInRange:range withString:string] intValue] * 2];
        return YES;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (PlayMethod == 6302) {
        return 60.0;
    }else {
        return 48.0;
    }
}

-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{
    return DELETE;
}

-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewCellEditingStyleDelete;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [numberArray count];
}

- (void)SelectFiveListItemCellDeleteButtonClicked:(NSNumber *)rowNumber{
    for (int i = [rowNumber intValue] + 1; i < [numberArray count]; ++i) {
        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
        UITableViewCell *cell = [lotNumListTableView cellForRowAtIndexPath:indexPath];
        cell.tag--;
    }
    
    [numberArray removeObjectAtIndex:[rowNumber intValue]];
    [lotNumListTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:[rowNumber intValue] inSection:0]] withRowAnimation:YES];
    //把新选择的号码添加进去，并从新计算注数
    //计算注数
    noteAmount = 0;
    for (JddFc3dNumber *inNums in numberArray) {
        switch (PlayMethod) {
            case 6302://直选
                noteAmount += [[inNums BallArray] count]*[[inNums SecondBallArray] count]*[[inNums ThirdBallArray] count];
                break;
            case 6305://组选三
                noteAmount += [[inNums BallArray] count]*([[inNums BallArray] count] - 1);
                break;
            case 6304://组选六
                if ([[inNums BallArray] count] > 2) {
                    noteAmount += [JddCommonFunction recurseBallNumber:[[inNums BallArray] count]combinationNumber:3];
                }
                break;
            default:
                break;
        }
        
    }
    moneyLabel.text = [NSString stringWithFormat:@"%d彩豆",noteAmount*2*[mutiTextField.text intValue]];
    countLabel.text = [NSString stringWithFormat:@"%d注",noteAmount];
    
}

-(void)SelectFive3ListItemCellDeleteButtonClicked:(NSNumber *)rowNumber{
    [self SelectFiveListItemCellDeleteButtonClicked:rowNumber];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (PlayMethod == 6302) {
        JddSelectFive3ListItemCell *cell = [JddSelectFive3ListItemCell getInstanceView];
        JddFc3dNumber *dltNumber = [numberArray objectAtIndex:indexPath.row];
        NSMutableString *BallNumberString = [NSMutableString stringWithCapacity:[dltNumber.BallArray count]];
        NSMutableString *SecondBallNumberString = [NSMutableString stringWithCapacity:[dltNumber.SecondBallArray count]];
        NSMutableString *ThirdBallNumberString = [NSMutableString stringWithCapacity:[dltNumber.ThirdBallArray count]];
        for (NSNumber *number in [JddCommonFunction sortArray: dltNumber.BallArray]) {
            [BallNumberString appendFormat:@"%d ", [number intValue]];
        }
        for (NSNumber *number in [JddCommonFunction sortArray: dltNumber.SecondBallArray]) {
            [SecondBallNumberString appendFormat:@"%d ", [number intValue]];
        }
        for (NSNumber *number in [JddCommonFunction sortArray: dltNumber.ThirdBallArray]) {
            [ThirdBallNumberString appendFormat:@"%d ", [number intValue]];
        }
        cell.SecondBallLabel.text = SecondBallNumberString;
        cell.ThirdBallLabel.text = ThirdBallNumberString;
        cell.BallLabel.text = BallNumberString;
        cell.PlayM = PlayMethod;
        cell.tag = indexPath.row;
        cell.delegate = self;
        return cell;
    }else{
        JddSelectFiveListItemCell *cell = [JddSelectFiveListItemCell getInstanceView];
        
        JddFc3dNumber *dltNumber = [numberArray objectAtIndex:indexPath.row];
        NSMutableString *BallNumberString = [NSMutableString stringWithCapacity:[dltNumber.BallArray count]];
        for (NSNumber *number in [JddCommonFunction sortArray: dltNumber.BallArray]) {
            [BallNumberString appendFormat:@"%d ", [number intValue]];
        }
        cell.BallLabel.text = BallNumberString;
        cell.PlayM = PlayMethod;
        cell.tag = indexPath.row;
        cell.delegate = self;
        
        return cell;
    }
}

- (IBAction)continueChooseBtnClick:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)addRandomBtnClick:(id)sender {
    UIButton* btn = sender;
    [btn setEnabled:NO];
    JddFc3dNumber *newNum = [[JddFc3dNumber alloc] init];
    switch (PlayMethod) {
        case 6302:
            [newNum addBallNumber:arc4random()%10];
            [newNum add2BallNumber:arc4random()%10];
            [newNum add3BallNumber:arc4random()%10];
            break;
        case 6305://组选三 至少选2个数字
            for (int i=0; i<2; i++) {
                BOOL redo = NO;
                do {
                    redo = NO;
                    NSInteger ranInt = 0;
                    ranInt = arc4random()%10;
                    if ([newNum BallHasNumber:ranInt]) {
                        redo = YES;
                    }else{
                        [newNum addBallNumber:ranInt];
                    }
                } while (YES == redo);
            }
            break;
            for (int i=0; i<3; i++) {
                BOOL redo = NO;
                do {
                    redo = NO;
                    NSInteger ranInt = 0;
                    ranInt = arc4random()%10;
                    if ([newNum BallHasNumber:ranInt]) {
                        redo = YES;
                    }else{
                        [newNum addBallNumber:ranInt];
                    }
                } while (YES == redo);
            }
            break;
        case 6304://组选六 至少选3个数字
            for (int i=0; i<3; i++) {
                BOOL redo = NO;
                do {
                    redo = NO;
                    NSInteger ranInt = 0;
                    ranInt = arc4random()%10;
                    if ([newNum BallHasNumber:ranInt]) {
                        redo = YES;
                    }else{
                        [newNum addBallNumber:ranInt];
                    }
                } while (YES == redo);
            }
            break;
        default:
            break;
    }
    [numberArray addObject:newNum];
    [lotNumListTableView reloadData];
    //把新选择的号码添加进去，并从新计算注数
    //计算注数
    noteAmount = 0;
    for (JddFc3dNumber *inNums in numberArray) {
        switch (PlayMethod) {
            case 6302://直选
                noteAmount += [[inNums BallArray] count]*[[inNums SecondBallArray] count]*[[inNums ThirdBallArray] count];
                break;
            case 6305://组选三
                noteAmount += [[inNums BallArray] count]*([[inNums BallArray] count] - 1);
                break;
            case 6304://组选六
                if ([[inNums BallArray] count] > 2) {
                    noteAmount += [JddCommonFunction recurseBallNumber:[[inNums BallArray] count]combinationNumber:3];
                }
                break;
            default:
                break;
        }
        
    }
    moneyLabel.text = [NSString stringWithFormat:@"%d彩豆",noteAmount*2*[mutiTextField.text intValue]];
    countLabel.text = [NSString stringWithFormat:@"%d注",noteAmount];
    [btn setEnabled:YES];
}

- (IBAction)reduceMutiBtnClick:(id)sender {
    NSInteger multiple = [mutiTextField.text intValue];
    if (multiple-- < 2) {
        mutiTextField.text = @"1";
        return;
    }
    mutiTextField.text = [NSString stringWithFormat:@"%d", multiple];
    moneyLabel.text = [NSString stringWithFormat:@"%d彩豆", noteAmount * multiple * 2];
}

- (IBAction)addMutiBtnClick:(id)sender {
    NSInteger multiple = [mutiTextField.text intValue];
    if (multiple>998) {
        return;
    }
    mutiTextField.text = [NSString stringWithFormat:@"%d", ++multiple];
    moneyLabel.text = [NSString stringWithFormat:@"%d彩豆", noteAmount * multiple * 2];
}

- (IBAction)clearBtnClick:(id)sender {
    if ([lotNumListTableView numberOfRowsInSection:0]>0) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
                                                        message:@"确认清空列表？"
                                                       delegate:self
                                              cancelButtonTitle:@"确定"
                                              otherButtonTitles:@"取消",nil ];
        [alert show];
    }
}

- (IBAction)doneBtnClick:(id)sender {
    int multiple = [mutiTextField.text intValue];
    if (![JddCommonFunction isLogin]) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
                                                        message:@"您还没有登录，请先登录"
                                                       delegate:self
                                              cancelButtonTitle:@"确定"
                                              otherButtonTitles:@"取消",nil ];
        [alert show];
    } else {
        if (!agreeLotteryForFooterView.checkBoxBtn.selected) {
            [JddCommonFunction messageBoxWithMessage:BUY_NOT_READ];
        }
        else if ([numberArray count]==0) {
            [JddCommonFunction messageBoxWithMessage:BALL_COUNT_NULL];
        }else{
            if (multiple == 0) {
                [JddCommonFunction messageBoxWithMessage:MULTIPLE_Tip];
            }else{
                [self sureToBuy];
                /*
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"玩球球"
                                                            message:@"确认购买？"
                                                           delegate:self
                                                  cancelButtonTitle:@"确定"
                                                  otherButtonTitles:@"取消",nil ];
            [alert show];*/
                }
        }
    }
}


-(BOOL)checkValue{
    if ([mutiTextField.text intValue]>999) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
                                                        message:@"倍数不能大于999"
                                                       delegate:nil
                                              cancelButtonTitle:@"确定"
                                              otherButtonTitles:nil,nil ];
        [alert show];
        mutiTextField.text =  @"999";
        return NO;
    }else if ((noteAmount * [mutiTextField.text intValue] * 2) > 2000000 ){
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
                                                        message:@"单个方案的总金额必须在2彩豆至2000000彩豆之间"
                                                       delegate:nil
                                              cancelButtonTitle:@"确定"
                                              otherButtonTitles:nil,nil ];
        [alert show];
        return NO;
    }
    return YES;
}

- (IBAction)editDoneTextField:(id)sender {
    [mutiTextField resignFirstResponder];
}

- (void)numberFromArray:(NSArray*)arrayTemp{
    isNeedAdd = true;
    if (!numberArrayTemp) {
        numberArrayTemp = [NSMutableArray array];
    }
    if (!numberArray) {
        numberArray = [[NSMutableArray alloc] init];
    }
    [numberArrayTemp removeAllObjects];
    [numberArrayTemp addObjectsFromArray:arrayTemp];
    if (PlayMethod==0||[numberArray count]==0) {
        //        [numberArray addObjectsFromArray:numberArrayTemp];
        PlayMethod=PlayMethodTemp;
        //        [lotNumListTableView reloadData];
        noteAmount = 0;
    }/*else if ([numberArray count] > 0){
      [numberArray addObjectsFromArray:numberArrayTemp];
      }*/
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
